/**
  @file    config.c
  @brief   
  @author  MediaTek
  @date    2016-06
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>

#include "global.h"



#define MAX_ITEMS_TO_PARSE  10000

int ParseRefContent(char **buf, int TemporalScalableFlag);

char *GetConfigFileContent_eqar(char *Filename)
{
#if MTK_ORIENTATION
  unsigned FileSize;
  FILE *f;
  char *buf;

  if ( NULL == ( f = fopen ( Filename, "r" ) ) )
  {
    printf ("Cannot open configuration file %s.\n", Filename );
    exit(0);
  }

  if ( 0 != fseek ( f, 0, SEEK_END ) )
  {
    printf ("Cannot fseek in configuration file %s.\n", Filename );
    exit(0);
  }

  FileSize = ftell ( f );

  if ( FileSize < 0 || FileSize > 60000 )
  {
    printf ("Unreasonable Filesize %d reported by ftell for configuration file %s.\n", FileSize, Filename );
    exit(0);
  }

  if ( 0 != fseek ( f, 0, SEEK_SET ) )
  {
    printf ("Cannot fseek in configuration file %s.\n", Filename );
    exit(0);
  }

  if ( ( buf = malloc ( FileSize + 1 ) ) == NULL )
  {
    printf("GetConfigFileContent: buf\n");
    exit(0);
  }

  // Note that ftell() gives us the file size as the file system sees it.  The actual file size,
  // as reported by fread() below will be often smaller due to CR/LF to CR conversion and/or
  // control characters after the dos EOF marker in the file.

  FileSize = fread ( buf, 1, FileSize, f );
  buf[FileSize] = '\0';

  fclose ( f );

  return buf;
#else
	return "eqar";
#endif
}

char *GetConfigFileContent_cube ( char *Filename )
{
  unsigned FileSize;
  FILE *f;
  char *buf;

  if ( NULL == ( f = fopen ( Filename, "r" ) ) )
  {
    printf ("Cannot open configuration file %s.\n", Filename );
    exit(0);
  }

  if ( 0 != fseek ( f, 0, SEEK_END ) )
  {
    printf ("Cannot fseek in configuration file %s.\n", Filename );
    exit(0);
  }

  FileSize = ftell ( f );

  if ( FileSize < 0 || FileSize > 60000 )
  {
    printf ("Unreasonable Filesize %d reported by ftell for configuration file %s.\n", FileSize, Filename );
    exit(0);
  }

  if ( 0 != fseek ( f, 0, SEEK_SET ) )
  {
    printf ("Cannot fseek in configuration file %s.\n", Filename );
    exit(0);
  }

  if ( ( buf = malloc ( FileSize + 1 ) ) == NULL )
  {
    printf("GetConfigFileContent: buf\n");
    exit(0);
  }

  // Note that ftell() gives us the file size as the file system sees it.  The actual file size,
  // as reported by fread() below will be often smaller due to CR/LF to CR conversion and/or
  // control characters after the dos EOF marker in the file.

  FileSize = fread ( buf, 1, FileSize, f );
  buf[FileSize] = '\0';

  fclose ( f );

  return buf;
}

#if asyerp
char *GetConfigFileContent_asyerp(char *Filename)
{
    unsigned FileSize;
    FILE *f;
    char *buf;

    if (NULL == (f = fopen(Filename, "r")))
    {
        printf("Cannot open configuration file %s.\n", Filename);
        exit(0);
    }

    if (0 != fseek(f, 0, SEEK_END))
    {
        printf("Cannot fseek in configuration file %s.\n", Filename);
        exit(0);
    }

    FileSize = ftell(f);

    if (FileSize < 0 || FileSize > 60000)
    {
        printf("Unreasonable Filesize %d reported by ftell for configuration file %s.\n", FileSize, Filename);
        exit(0);
    }

    if (0 != fseek(f, 0, SEEK_SET))
    {
        printf("Cannot fseek in configuration file %s.\n", Filename);
        exit(0);
    }

    if ((buf = malloc(FileSize + 1)) == NULL)
    {
        printf("GetConfigFileContent: buf\n");
        exit(0);
    }

    // Note that ftell() gives us the file size as the file system sees it.  The actual file size,
    // as reported by fread() below will be often smaller due to CR/LF to CR conversion and/or
    // control characters after the dos EOF marker in the file.

    FileSize = fread(buf, 1, FileSize, f);
    buf[FileSize] = '\0';

    fclose(f);

    return buf;
}
#endif

char *GetConfigFileContent_asc(char *Filename)
{
	unsigned FileSize;
	FILE *f;
	char *buf;

	if (NULL == (f = fopen(Filename, "r")))
	{
		printf("Cannot open configuration file %s.\n", Filename);
		exit(0);
	}

	if (0 != fseek(f, 0, SEEK_END))
	{
		printf("Cannot fseek in configuration file %s.\n", Filename);
		exit(0);
	}

	FileSize = ftell(f);

	if (FileSize < 0 || FileSize > 60000)
	{
		printf("Unreasonable Filesize %d reported by ftell for configuration file %s.\n", FileSize, Filename);
		exit(0);
	}

	if (0 != fseek(f, 0, SEEK_SET))
	{
		printf("Cannot fseek in configuration file %s.\n", Filename);
		exit(0);
	}

	if ((buf = malloc(FileSize + 1)) == NULL)
	{
		printf("GetConfigFileContent: buf\n");
		exit(0);
	}

	// Note that ftell() gives us the file size as the file system sees it.  The actual file size,
	// as reported by fread() below will be often smaller due to CR/LF to CR conversion and/or
	// control characters after the dos EOF marker in the file.

	FileSize = fread(buf, 1, FileSize, f);
	buf[FileSize] = '\0';

	fclose(f);

	return buf;
}

#if ISP
char *GetConfigFileContent_isp(char *Filename)
{
	return "isp";
}
#endif
void CubicMappingInfo(configureInfo *cfi)
{
  int i, j;
  int layoutWidthArray[4] = {1, 2, 3, 6};
  int defaultCubicLayout[4][6] =   {{0,1,2,4,3,5},
                                    {0,4,1,3,2,5},
                                    {0,1,2,4,3,5},
                                    {0,1,2,4,3,5}};
  int defaultCubicRotation[4][6] = {{1,1,1,3,0,3},
                                    {1,3,1,0,1,3},
                                    {0,0,0,1,2,1},
                                    {0,0,0,1,2,1}};
  
  cfi->layoutWidth = layoutWidthArray[cfi->CubicType];
    if (cfi->DefaultCubicLayoutFlag) {
      for (i=0; i<6; i++) {
          cfi->CubicFaceOrder[i] = defaultCubicLayout[cfi->CubicType][i];
        cfi->CubicFaceRotation[i] = defaultCubicRotation[cfi->CubicType][i];
      }
  }
  printf("Cubic layout: ");
  for (i=0; i<6; i++) printf("%d ", cfi->CubicFaceOrder[i]);
  printf("\nCubic rotation: ");
  for (i=0; i<6; i++) printf("%d ", cfi->CubicFaceRotation[i]);
  printf("\n");

  // remap to original VRM face definition
  for (j=0; j<6; j++)
    cfi->CubicFaceOrder[j] = (cfi->CubicFaceOrder[j]<2) ? cfi->CubicFaceOrder[j]+2 : 
                           ((cfi->CubicFaceOrder[j]<4) ? cfi->CubicFaceOrder[j]-2 : cfi->CubicFaceOrder[j]);
  for (j=0; j<6; j++)
    for (i=0; i<6; i++)
      if (j==cfi->CubicFaceOrder[i]) {
          cfi->layout_array[j] = i;
        cfi->layout_rotate[j] = cfi->CubicFaceRotation[i];
      }
}

#if doublering

char *GetConfigFileContent_doublering(char *Filename)
{
	return "doublering";
}

void ParseContent_doublering(char *buf, int bufsize, configureInfo *cfi)
{

}

#endif
#if MTK_SS_CUBE

char *GetConfigFileContent_ssCube(char *Filename)
{
  unsigned FileSize;
  FILE *f;
  char *buf;

  if ( NULL == ( f = fopen ( Filename, "r" ) ) )
  {
    printf ("Cannot open configuration file %s.\n", Filename );
    exit(0);
  }

  if ( 0 != fseek ( f, 0, SEEK_END ) )
  {
    printf ("Cannot fseek in configuration file %s.\n", Filename );
    exit(0);
  }

  FileSize = ftell ( f );

  if ( FileSize < 0 || FileSize > 60000 )
  {
    printf ("Unreasonable Filesize %d reported by ftell for configuration file %s.\n", FileSize, Filename );
    exit(0);
  }

  if ( 0 != fseek ( f, 0, SEEK_SET ) )
  {
    printf ("Cannot fseek in configuration file %s.\n", Filename );
    exit(0);
  }

  if ( ( buf = malloc ( FileSize + 1 ) ) == NULL )
  {
    printf("GetConfigFileContent: buf\n");
    exit(0);
  }

  // Note that ftell() gives us the file size as the file system sees it.  The actual file size,
  // as reported by fread() below will be often smaller due to CR/LF to CR conversion and/or
  // control characters after the dos EOF marker in the file.

  FileSize = fread ( buf, 1, FileSize, f );
  buf[FileSize] = '\0';

  fclose ( f );

  return buf;
}

void ParseContent_ssCube(char *buf, int bufsize, configureInfo *cfi)
{
	char *items[MAX_ITEMS_TO_PARSE];
	int item = 0;
	int InString = 0;
	int InItem = 0;
	char *p = buf;
	char *bufend = &buf[bufsize];
	int i;

	// Stage one: Generate an argc/argv-type list in items[], without comments and whitespace.
	// This is context insensitive and could be done most easily with lex(1).

	while (p < bufend)
	{
		switch (*p)
		{
		case 13:
			p++;
			break;
		case '#':                 // Found comment
			*p = '\0';              // Replace '#' with '\0' in case of comment immediately following integer or string

			while (*p != '\n' && p < bufend) // Skip till EOL or EOF, whichever comes first
			{
				p++;
			}

			InString = 0;
			InItem = 0;
			break;
		case '\n':
			InItem = 0;
			InString = 0;
			*p++ = '\0';
			break;
		case ' ':
		case '\t':              // Skip whitespace, leave state unchanged

			if (InString)
			{
				p++;
			}
			else
			{
				// Terminate non-strings once whitespace is found
				*p++ = '\0';
				InItem = 0;
			}

			break;
		case '"':               // Begin/End of String
			*p++ = '\0';

			if (!InString)
			{
				items[item++] = p;
				InItem = ~InItem;
			}
			else
			{
				InItem = 0;
			}

			InString = ~InString; // Toggle
			break;
		default:

			if (!InItem)
			{
				items[item++] = p;
				InItem = ~InItem;
			}

			p++;
		}
	}

	item--;

	for (i = 0; i < item; i += 3) {
		if (0 == strcmp(items[i], "Viewpoint_centre_lon")) {
			cfi->Viewpoint_center_longitude = atoi(items[i + 2]);
		}
		if (0 == strcmp(items[i], "Viewpoint_centre_lat")) {
			cfi->Viewpoint_center_latitude = atoi(items[i + 2]);
		}
		if (0 == strcmp(items[i], "SSCUBE_XFACTOR")) {
			cfi->x_factor =  atoi(items[i + 2]);
		}
		if (i >= item)
			break;
	}
}

#endif

void ParseContent_eqar(char *buf, int bufsize, configureInfo *cfi)
{
#if MTK_ORIENTATION
  char *items[MAX_ITEMS_TO_PARSE];
  int item = 0;
  int InString = 0;
  int InItem = 0;
  char *p = buf;
  char *bufend = &buf[bufsize];
  int i;

  // Stage one: Generate an argc/argv-type list in items[], without comments and whitespace.
  // This is context insensitive and could be done most easily with lex(1).

  while (p < bufend)
  {
    switch (*p)
    {
    case 13:
      p++;
      break;
    case '#':                 // Found comment
      *p = '\0';              // Replace '#' with '\0' in case of comment immediately following integer or string

      while (*p != '\n' && p < bufend) // Skip till EOL or EOF, whichever comes first
      {
        p++;
      }

      InString = 0;
      InItem = 0;
      break;
    case '\n':
      InItem = 0;
      InString = 0;
      *p++ = '\0';
      break;
    case ' ':
    case '\t':              // Skip whitespace, leave state unchanged

      if (InString)
      {
        p++;
      }
      else
      {
        // Terminate non-strings once whitespace is found
        *p++ = '\0';
        InItem = 0;
      }

      break;
    case '"':               // Begin/End of String
      *p++ = '\0';

      if (!InString)
      {
        items[item++] = p;
        InItem = ~InItem;
      }
      else
      {
        InItem = 0;
      }

      InString = ~InString; // Toggle
      break;
    default:

      if (!InItem)
      {
        items[item++] = p;
        InItem = ~InItem;
      }

      p++;
    }
  }

  item--;

  for (i = 0; i < item; i += 1) 
  {
    if (0 == strcmp(items[i], "AutoRotation"))
      cfi->orientation_detection = atoi(items[i + 2]);
    
    if (0 == strcmp(items[i], "Transformation"))
      cfi->transformation = atoi(items[i + 2]);
    
    if (0 == strcmp(items[i], "RotationRoll"))
      cfi->rotation_roll = atoi(items[i + 2]);
    
    if (0 == strcmp(items[i], "RotationYaw"))
      cfi->rotation_yaw = atoi(items[i + 2]);
    
    if (0 == strcmp(items[i], "RotationPitch"))
      cfi->rotation_pitch = atoi(items[i + 2]);

    if (i >= item)
      break;
  }
#endif
}

void ParseContent_cube (char *buf, int bufsize, configureInfo *cfi)
{
  char *items[MAX_ITEMS_TO_PARSE];
  int item     = 0;
  int InString = 0;
  int InItem   = 0;
  char *p      = buf;
  char *bufend = &buf[bufsize];
  int i, j;

  char headstr[10] = {'F','r','a','m','e', '1', ':', '\0'};
  char temporalstr[21] = {'T','e','m','p','o','r','a','l','S','c','a','l','a','b','l','e','F','l','a','g','\0'};
  int TemporalFlag = 0;
  int MappingFormat = 0;

  char MappingFormatstr[32]= "MappingFormat";
  char CubicTypestr[32] = "CubicType";
  char DefaultCubicLayoutFlagstr[32] = "DefaultCubicLayoutFlag";
  char FaceOrderstr[32] = "CubicFaceOrder";
  char FaceRotationstr[32] = "CubicFaceRotation";


  // Stage one: Generate an argc/argv-type list in items[], without comments and whitespace.
  // This is context insensitive and could be done most easily with lex(1).

  while ( p < bufend )
  {
    switch ( *p )
    {
    case 13:
      p++;
      break;
    case '#':                 // Found comment
      *p = '\0';              // Replace '#' with '\0' in case of comment immediately following integer or string

      while ( *p != '\n' && p < bufend ) // Skip till EOL or EOF, whichever comes first
      {
        p++;
      }

      InString = 0;
      InItem = 0;
      break;
    case '\n':
      InItem = 0;
      InString = 0;
      *p++ = '\0';
      break;
    case ' ':
    case '\t':              // Skip whitespace, leave state unchanged

      if ( InString )
      {
        p++;
      }
      else
      {
        // Terminate non-strings once whitespace is found
        *p++ = '\0';
        InItem = 0;
      }

      break;
    case '"':               // Begin/End of String
      *p++ = '\0';

      if ( !InString )
      {
        items[item++] = p;
        InItem = ~InItem;
      }
      else
      {
        InItem = 0;
      }

      InString = ~InString; // Toggle
      break;
    default:

      if ( !InItem )
      {
        items[item++] = p;
        InItem = ~InItem;
      }

      p++;
    }
  }

  item--;

  for ( i = 0; i < item; i += 3 ) {
    if (0 == strcmp(items[i], temporalstr))
        TemporalFlag = atoi(items[i+2]);
    if (0 == strcmp(items[i], headstr))
      i += ParseRefContent(&items[i], TemporalFlag);

    if (0 == strcmp(items[i], MappingFormatstr))
        MappingFormat = atoi(items[i+2]);

    // cubic format
    if (0 == strcmp(items[i], CubicTypestr))
        cfi->CubicType = atoi(items[i+2]);
    if (0 == strcmp(items[i], DefaultCubicLayoutFlagstr))
        cfi->DefaultCubicLayoutFlag = atoi(items[i+2]);
    if (0 == strcmp(items[i], FaceOrderstr)) {
		for (j = 0; j < NUM_CUBIC_FACE; j++)
			cfi->CubicFaceOrder[j] = items[i + 2][j] - '0';
    }
    if (0 == strcmp(items[i], FaceRotationstr)) {
		for (j = 0; j < NUM_CUBIC_FACE; j++)
			cfi->CubicFaceRotation[j] = items[i + 2][j] - '0';
    }

    if (i >= item)
          break;
  }
  if (MappingFormat==0) // cube
    CubicMappingInfo(cfi);
  else {
    printf("Not supported mapping format.\n");
  exit(0);
  }

}

#if asyerp
void ParseContent_asyerp(char *buf, int bufsize, configureInfo *cfi)
{
    char *items[MAX_ITEMS_TO_PARSE];
    int item = 0;
    int InString = 0;
    int InItem = 0;
    char *p = buf;
    char *bufend = &buf[bufsize];
    int i;

    // Stage one: Generate an argc/argv-type list in items[], without comments and whitespace.
    // This is context insensitive and could be done most easily with lex(1).

    while (p < bufend)
    {
        switch (*p)
        {
        case 13:
            p++;
            break;
        case '#':                 // Found comment
            *p = '\0';              // Replace '#' with '\0' in case of comment immediately following integer or string

            while (*p != '\n' && p < bufend) // Skip till EOL or EOF, whichever comes first
            {
                p++;
            }

            InString = 0;
            InItem = 0;
            break;
        case '\n':
            InItem = 0;
            InString = 0;
            *p++ = '\0';
            break;
        case ' ':
        case '\t':              // Skip whitespace, leave state unchanged

            if (InString)
            {
                p++;
            }
            else
            {
                // Terminate non-strings once whitespace is found
                *p++ = '\0';
                InItem = 0;
            }

            break;
        case '"':               // Begin/End of String
            *p++ = '\0';

            if (!InString)
            {
                items[item++] = p;
                InItem = ~InItem;
            }
            else
            {
                InItem = 0;
            }

            InString = ~InString; // Toggle
            break;
        default:

            if (!InItem)
            {
                items[item++] = p;
                InItem = ~InItem;
            }

            p++;
        }
    }

    item--;

    for (i = 0; i < item; i += 3) {
        // cubic format
        if (0 == strcmp(items[i], "ROIW"))
            cfi->roi_width = atoi(items[i + 2]);
        if (0 == strcmp(items[i], "ROIH"))
            cfi->roi_height = atoi(items[i + 2]);
        if (0 == strcmp(items[i], "ASCERP_VWIDTH")) {
            cfi->visual_width = atoi(items[i + 2]);
        }
        if (0 == strcmp(items[i], "ASCERP_VHEIGHT")) {
            cfi->visual_height = atoi(items[i + 2]);
        }

        if (i >= item)
            break;
    }
}
#endif

#if ASC
void ParseContent_asc(char *buf, int bufsize, configureInfo *cfi)
{
	char *items[MAX_ITEMS_TO_PARSE];
	int item = 0;
	int InString = 0;
	int InItem = 0;
	char *p = buf;
	char *bufend = &buf[bufsize];
	int i;

	// Stage one: Generate an argc/argv-type list in items[], without comments and whitespace.
	// This is context insensitive and could be done most easily with lex(1).

	while (p < bufend)
	{
		switch (*p)
		{
		case 13:
			p++;
			break;
		case '#':                 // Found comment
			*p = '\0';              // Replace '#' with '\0' in case of comment immediately following integer or string

			while (*p != '\n' && p < bufend) // Skip till EOL or EOF, whichever comes first
			{
				p++;
			}

			InString = 0;
			InItem = 0;
			break;
		case '\n':
			InItem = 0;
			InString = 0;
			*p++ = '\0';
			break;
		case ' ':
		case '\t':              // Skip whitespace, leave state unchanged

			if (InString)
			{
				p++;
			}
			else
			{
				// Terminate non-strings once whitespace is found
				*p++ = '\0';
				InItem = 0;
			}

			break;
		case '"':               // Begin/End of String
			*p++ = '\0';

			if (!InString)
			{
				items[item++] = p;
				InItem = ~InItem;
			}
			else
			{
				InItem = 0;
			}

			InString = ~InString; // Toggle
			break;
		default:

			if (!InItem)
			{
				items[item++] = p;
				InItem = ~InItem;
			}

			p++;
		}
	}

	item--;

	for (i = 0; i < item; i += 3) {
		// cubic format
		if (0 == strcmp(items[i], "ASC_Z1"))
			cfi->ASC_Z1 = atoi(items[i + 2]);
		if (0 == strcmp(items[i], "ASC_Z2"))
			cfi->ASC_Z2 = atoi(items[i + 2]);
		if (0 == strcmp(items[i], "ASC_p1")) {
			cfi->ASC_p1 = atoi(items[i + 2]);
		}
		if (0 == strcmp(items[i], "Viewpoint_centre_lon")) {
			cfi->Viewpoint_center_longitude = atoi(items[i + 2]);
		}
		if (0 == strcmp(items[i], "Viewpoint_centre_lat")) {
			cfi->Viewpoint_center_latitude = atoi(items[i + 2]);
		}
		if (i >= item)
			break;
	}
}
#endif

#if ISP
void ParseContent_isp(char *buf, int bufsize, configureInfo *cfi)
{
	return;
}
#endif
/************************************************************************************/
int ParseRefContent(char **buf, int TemporalScalableFlag)
{
  int num_of_ref, num_to_remove;
  int i = 1;
  int j = 0;
  char* token;
  char **p = buf;
  char* tmp_str=":";
  char str[3];
  char headstr[10]={'F','r','a','m','e','\0','\0','\0','\0','\0'};

// Fix by Sunil for RD5.0 test in Linux (2013.11.06)
#ifdef WIN32
  _itoa(i,str,10);//ZHAOHAIWU
#else
  sprintf(str,"%d",i);
#endif
  strcat(headstr,str);
  strcat(headstr,tmp_str);

  while (0 == strcmp(headstr, *p++))
  {
    //tmp = cfg_ref_all+i-1;
    token = *p++;
    //tmp->poc = atoi(token);
    token = *p++;
    //tmp->qp_offset = atoi(token);
    token = *p++;
    num_of_ref = atoi(token);
    token = *p++;
    //tmp->referd_by_others = atoi(token);
    for (j=0; j<num_of_ref; j++)
    {
      token =  *p++;
      //tmp->ref_pic[j] = atoi(token);
    }



    token = *p++;
    num_to_remove = atoi(token);
    for (j=0;j<num_to_remove;j++)
    {
      token =  *p++;
      //tmp->remove_pic[j] = atoi(token);
    }

#if 1 //M3480_TEMPORAL_SCALABLE
    if( TemporalScalableFlag == 1 )
    {
      token =  *p++;
      //tmp->temporal_id = atoi(token);
    }
#endif

    i++;
    headstr[5] = headstr[6] = headstr[7] = headstr[8] = headstr[9] = '\0';
// Fix by Sunil for RD5.0 test in Linux (2013.11.06)
#ifdef WIN32
    _itoa(i,str,10);//ZHAOHAIWU
#else
        sprintf(str,"%d",i);
#endif
    strcat(headstr,str);
    strcat(headstr,tmp_str);
  }

  return (p-buf-1);
}

#if POLERECT

char *GetConfigFileContent_polerect(char *Filename)
{
	return "polerect";
}

void ParseContent_polerect(char *buf, int bufsize, configureInfo *cfi)
{

}

#endif

void init_function_cfi(sourceInfo *input_Info, sourceInfo *output_Info){
	// init input function
	if (!strcmp(input_Info->format, "eqar")){
		handle_function.GetConfigFileContent_in = GetConfigFileContent_eqar;
		handle_function.ParseContent_in = ParseContent_eqar;
	}
#if asyerp
    else if (!strcmp(input_Info->format, "asyerp")){
        handle_function.GetConfigFileContent_in = GetConfigFileContent_asyerp;
        handle_function.ParseContent_in = ParseContent_asyerp;
    }
#endif
	else if (!strcmp(input_Info->format, "cube")){
		handle_function.GetConfigFileContent_in = GetConfigFileContent_cube;
		handle_function.ParseContent_in = ParseContent_cube;
	}

#if doublering

	else if (!strcmp(input_Info->format, "doublering")){
		handle_function.GetConfigFileContent_in = GetConfigFileContent_doublering;
		handle_function.ParseContent_in = ParseContent_doublering;
	}

#endif

#if POLERECT
	else if (!strcmp(input_Info->format, "polerect")){
		handle_function.GetConfigFileContent_in = GetConfigFileContent_polerect;
		handle_function.ParseContent_in = ParseContent_polerect;
	}
#endif

#if ASC
	else if (!strcmp(input_Info->format, "asc")){
		handle_function.GetConfigFileContent_in = GetConfigFileContent_asc;
		handle_function.ParseContent_in = ParseContent_asc;
	}
#endif

#if ISP
	else if (!strcmp(input_Info->format, "isp")){
		handle_function.GetConfigFileContent_in = GetConfigFileContent_isp;
		handle_function.ParseContent_in = ParseContent_isp;
	}
#endif
#if MTK_SS_CUBE
	else if (!strcmp(input_Info->format, "ssCube")){
		handle_function.GetConfigFileContent_in = GetConfigFileContent_ssCube;
		handle_function.ParseContent_in = ParseContent_ssCube;
	}

#endif
	// init output function
	if (!strcmp(output_Info->format, "eqar")){
		handle_function.GetConfigFileContent_out = GetConfigFileContent_eqar;
		handle_function.ParseContent_out = ParseContent_eqar;
	}
	else if (!strcmp(output_Info->format, "cube")){
		handle_function.GetConfigFileContent_out = GetConfigFileContent_cube;
		handle_function.ParseContent_out = ParseContent_cube;
	}
#if asyerp
    else if (!strcmp(output_Info->format, "asyerp")){
        handle_function.GetConfigFileContent_out = GetConfigFileContent_asyerp;
        handle_function.ParseContent_out = ParseContent_asyerp;
    }
#endif

#if doublering

	else if (!strcmp(output_Info->format, "doublering")){
		handle_function.GetConfigFileContent_out = GetConfigFileContent_doublering;
		handle_function.ParseContent_out = ParseContent_doublering;
	}

#endif

#if POLERECT
	else if (!strcmp(output_Info->format, "polerect")){
		handle_function.GetConfigFileContent_out = GetConfigFileContent_polerect;
		handle_function.ParseContent_out = ParseContent_polerect;
	}
#endif

#if ASC
	else if (!strcmp(output_Info->format, "asc")){
		handle_function.GetConfigFileContent_out = GetConfigFileContent_asc;
		handle_function.ParseContent_out = ParseContent_asc;
	}
#endif

#if ISP
	else if (!strcmp(output_Info->format, "isp")){
		handle_function.GetConfigFileContent_out = GetConfigFileContent_isp;
		handle_function.ParseContent_out = ParseContent_isp;
	}
#endif
#if MTK_SS_CUBE
	else if (!strcmp(output_Info->format, "ssCube")){
		handle_function.GetConfigFileContent_out = GetConfigFileContent_ssCube;
		handle_function.ParseContent_out = ParseContent_ssCube;
	}

#endif
}

